import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import permission from './directive/permission'
import '@/icons' // icon
import '@/permission' // permission control
import printPage from "@/utils/printPage"
import api from './api'

const echarts = require('echarts/lib/echarts')
require('echarts/lib/chart/bar')			// 柱状图
require('echarts/lib/chart/line')			// 饼图
require('echarts/lib/chart/pie')
// 下面的是需要的提示框
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/legend')
require('echarts/lib/component/grid')
require('echarts/lib/component/toolbox')

// 挂载全局组件
import '@/components/common'

Vue.use(permission)
Vue.use(printPage)
// 撤销审批公共方法
import undo from '@/assets/js/undo'

import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  download,
  handleTree,
  dateFormat1,
  conversionTime,
  checkDetailPermis
} from '@/utils/ruoyi'

// 全局方法挂载
Vue.prototype.$comFun = undo
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.dateFormat1 = dateFormat1
Vue.prototype.conversionTime = conversionTime
Vue.prototype.checkDetailPermis = checkDetailPermis
Vue.prototype.$api = api
Vue.prototype.$echarts = echarts

Vue.prototype.$back = function (route) {
  console.log(route)
  if (window.history.length > 1) {
    this.$router.back();
  } else {
    this.$router.push(route);
  }
}

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
ElementUI.Dialog.props.closeOnClickModal.default = false
Vue.use(ElementUI, { size: 'small' })

// 全局修改message配置
const offsets = 100
Vue.prototype.$message = function(options) {
  if (typeof options === 'object') {
    return ElementUI.Message({
      ...options,
      offset: offsets
    })
  } else if (typeof options === 'string') {
    return ElementUI.Message({
      message: options,
      offset: offsets
    })
  }
}
Vue.prototype.$message.success = function(msg) {
  return ElementUI.Message.success({
    message: msg,
    offset: offsets
  })
}
Vue.prototype.$message.error = function(msg) {
  return ElementUI.Message.error({
    message: msg,
    offset: offsets
  })
}
Vue.prototype.$message.warning = function(msg) {
  return ElementUI.Message.warning({
    message: msg,
    offset: offsets
  })
}

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
